import java.io.IOException; 
import java.text.ParseException; 
  
import org.apache.hadoop.mapreduce.InputSplit; 
import org.apache.hadoop.mapreduce.RecordReader; 
import org.apache.hadoop.mapreduce.TaskAttemptContext; 
  
class DateUrlLineRecordReader extends RecordReader<DateWritableComparable,URLWritable> { 
   
    KeyValueTextRecordReader reader; 
     
    public DateUrlLineRecordReader() { 
      super(); 
      reader = new KeyValueTextRecordReader(); 
  } 
   
    @Override 
    public void initialize(InputSplit genericSplit, TaskAttemptContext context) throws IOException { 
        reader.initialize(genericSplit, context); 
    } 
         
    @Override 
    public boolean nextKeyValue() throws IOException { 
        return reader.nextKeyValue(); 
    } 
  
    @Override 
    public DateWritableComparable getCurrentKey() throws IOException, InterruptedException { 
        try { 
            return new DateWritableComparable(reader.getCurrentKey().toString()); 
        } catch (ParseException e) { 
            return null; 
        } 
    } 
  
    @Override 
    public URLWritable getCurrentValue() throws IOException, InterruptedException { 
        return new URLWritable(reader.getCurrentKey().toString()); 
    } 
  
    @Override 
      public float getProgress() throws IOException { 
        return reader.getProgress(); 
      } 
   
  @Override 
  public void close() throws IOException { 
    reader.close(); 
  } 
}
